#include "stdafx.h"
#include "HeroCardDef.h"
#include "MgrBase.h"
#include "ValidatorBase.h"

struct HeroCardDefReflectionRegister
{
	HeroCardDefReflectionRegister()
	{
		REGISTER_REFLECTION_MEMBER(HeroCardTypeDef,m_iID,INVALID_ID).Editor_SetAsPrimaryKey();
		REGISTER_REFLECTION_MEMBER(HeroCardTypeDef,m_sDisplayName,std::string("DefaultName")).Editor_SetAsDisplayName();
		REGISTER_REFLECTION_MEMBER(HeroCardTypeDef,m_sName,std::string("GameName")).Editor_SetAsRaw();
		REGISTER_REFLECTION_MEMBER(HeroCardTypeDef,m_eRace,eRuneRace_Earth).Editor_SetAsEnumation<ERuneRace>();
		REGISTER_REFLECTION_MEMBER(HeroCardTypeDef,m_iStar,1).Editor_SetAsRaw();
		REGISTER_REFLECTION_MEMBER(HeroCardTypeDef,m_iInitHp,100).Editor_SetAsRaw();
		REGISTER_REFLECTION_MEMBER(HeroCardTypeDef,m_iGrowHp,10).Editor_SetAsRaw();
		REGISTER_REFLECTION_MEMBER(HeroCardTypeDef,m_sPicID,std::string("DefaultPic")).Editor_SetAsRaw();
		REGISTER_REFLECTION_MEMBER(HeroCardTypeDef,m_iShape,0).Editor_SetAsRaw();
		REGISTER_REFLECTION_MEMBER(HeroCardTypeDef,m_sDesc,std::string("default desc")).Editor_SetAsRaw();
		REGISTER_REFLECTION_MEMBER(HeroCardTypeDef,m_iSellPrice,100).Editor_SetAsRaw();
		REGISTER_REFLECTION_MEMBER(HeroCardTypeDef,m_vSource,std::vector<int32>()).Editor_SetAsForeignKeySet(eDefGroup_Default,eDefaultDef_DropSource);
		REGISTER_REFLECTION_MEMBER(HeroCardTypeDef,m_iLibraryIndex,INVALID_ID).Editor_SetAsRaw();
		REGISTER_REFLECTION_MEMBER(HeroCardTypeDef,m_eUsage,EHeroUsage_Normal).Editor_SetAsEnumation<EHeroUsage>();

		REGISTER_REFLECTION_MEMBER(HeroCardDef,m_iID,INVALID_ID).Editor_SetAsPrimaryKey();
		REGISTER_REFLECTION_MEMBER(HeroCardDef,m_sDisplayName,std::string("DefaultName")).Editor_SetAsDisplayName();
		REGISTER_REFLECTION_MEMBER(HeroCardDef,m_iTypeID,INVALID_ID).Editor_SetAsForeignKey(eDefGroup_Default,eDefaultDef_HeroTypes);
		REGISTER_REFLECTION_MEMBER(HeroCardDef,m_iLv,0).Editor_SetAsRaw();
		
		REGISTER_REFLECTION_MEMBER(HeroCardDef,m_iInateSkill1,INVALID_ID).Editor_SetAsForeignKey(eDefGroup_Default,eDefaultDef_InnateSkill,"Innate");
		REGISTER_REFLECTION_MEMBER(HeroCardDef,m_iInateSkill2,INVALID_ID).Editor_SetAsForeignKey(eDefGroup_Default,eDefaultDef_InnateSkill,"Innate");
		REGISTER_REFLECTION_MEMBER(HeroCardDef,m_iInateSkill3,INVALID_ID).Editor_SetAsForeignKey(eDefGroup_Default,eDefaultDef_InnateSkill,"Innate");
		REGISTER_REFLECTION_MEMBER(HeroCardDef,m_iInateSkill4,INVALID_ID).Editor_SetAsForeignKey(eDefGroup_Default,eDefaultDef_InnateSkill,"Innate");

		REGISTER_REFLECTION_MEMBER(HeroCardDef,m_iSkillID1,INVALID_ID).Editor_SetAsForeignKey(eDefGroup_Default,eDefaultDef_Reactors,"Skills");
		REGISTER_REFLECTION_MEMBER(HeroCardDef,m_iSp1,100).Editor_SetAsRaw("Skills");
		REGISTER_REFLECTION_MEMBER(HeroCardDef,m_iSkillID2,INVALID_ID).Editor_SetAsForeignKey(eDefGroup_Default,eDefaultDef_Reactors,"Skills");
		REGISTER_REFLECTION_MEMBER(HeroCardDef,m_iSp2,100).Editor_SetAsRaw("Skills");

		REGISTER_REFLECTION_MEMBER(HeroCardDef,m_iExpToNextLv,0).Editor_SetAsRaw("Msic");
		REGISTER_REFLECTION_MEMBER(HeroCardDef,m_iExpUsed,0).Editor_SetAsRaw("Msic");
		REGISTER_REFLECTION_MEMBER(HeroCardDef,m_iCostHnUsed,0).Editor_SetAsRaw("Msic");
		REGISTER_REFLECTION_MEMBER(HeroCardDef,m_fCombatPower,1.f).Editor_SetAsRaw("Msic");
		REGISTER_REFLECTION_MEMBER(HeroCardDef,m_iInitRage,50).Editor_SetAsRaw("Msic");
		REGISTER_REFLECTION_MEMBER(HeroCardDef,m_iResolveNum, 1).Editor_SetAsRaw("Msic");

		GlobalClassManager::Instance().RegisterClass(HeroCardDef::s_GetReflection(),eDefaultDef_HeroCard);
		GlobalDefManager::Instance().RegisterDefManger(&HeroCardDefManager::Instance());

		GlobalClassManager::Instance().RegisterClass(HeroCardTypeDef::s_GetReflection(),eDefaultDef_HeroTypes);
		GlobalDefManager::Instance().RegisterDefManger(&HeroTypeDefManager::Instance());

	}
}_____runedefreflectionregister;

rewrite  void HeroCardDef::OnArchieveReaded()
{
	m_pType=HeroTypeDefManager::Instance().LookupItem(m_iTypeID);
}


#define MAKE_HEROCARD_TYPE_LEVEL_ID(type,level) (1000*type+level)
const HeroCardDef * HeroCardDefManager::LookupHeroCardDefByLvl( int32 iType,int32 iLevel ) const
{
	std::map<int32,const HeroCardDef *>::const_iterator it= m_mIndexs.find(MAKE_HEROCARD_TYPE_LEVEL_ID(iType,iLevel));
	if(it==m_mIndexs.end()) return NULL;
	return it->second;
}

rewrite  void HeroCardDefManager::OnArchieveReaded()
{
	__HeroCardDefManager::OnArchieveReaded();
	m_mIndexs.clear();
	std::vector<const HeroCardDef*> vEnum;
	Enumerate(vEnum);
	for(uint32 ii=0;ii<vEnum.size();ii++)
	{
		m_mIndexs[MAKE_HEROCARD_TYPE_LEVEL_ID(vEnum[ii]->m_iTypeID,vEnum[ii]->m_iLv)]=vEnum[ii];
	}
}